#include <assert.h>
#include <string.h>

#include "iris_interface.h"
#include "../cache/hash_table.h"
#include "../cache/mreq.h"
#include "../glue/sim.h"

extern Simulator Sim;

/********************
 * Bus_network Interface
 ********************/
Iris_interface::Iris_interface (Network *my_net, ModuleID moduleID)
    : Network_interface(my_net, moduleID, "FI_")
{
}

Iris_interface::~Iris_interface ()
{
}

void Iris_interface::tick ()
{
    Mreq *request;
    
    while ((request = read_input_port ()) != NULL)
    {
        ((Iris_interface *) my_net->get_interface(request->dest_mid.nodeID))->in_request_queue.push(request);
    }
}

void Iris_interface::tock ()
{
    Mreq *request;
    while (!in_request_queue.empty()) 
    {
        request = in_request_queue.front ();
        in_request_queue.pop ();

        assert (request->dest_mid.nodeID == moduleID.nodeID && "wrong destination?");
        //request->add_to_history(request, "fakenet");
        write_output_port (request, Global_Clock + 10);
    }
}
